package com.admin.education.controllers.api.v1;

import com.admin.education.common.exceptions.BadRequestException;
import com.admin.education.common.jwt.JwtAuthorize;
import com.admin.education.common.response.IResponseMessage;
import com.admin.education.common.response.ResponseMessageWithData;
import com.admin.education.common.response.Result;
import com.admin.education.dataTransferObject.ServicesExcuteResult;
import com.admin.education.dataTransferObject.grades.GradesTransfer;
import com.admin.education.services.Interfaces.IGradesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

@RestController
@RequestMapping("/v1/grades")
@JwtAuthorize
public class GradeController {
    @Autowired
    private IGradesService gradesService;
    @GetMapping("")
    public Callable<IResponseMessage> queryGrades(){
        return ()->{
            IResponseMessage responseMessage = null;
            ServicesExcuteResult<List<GradesTransfer>> result = this.gradesService.queryGrades();
            if(result.isSuccess()){
                responseMessage = new ResponseMessageWithData<List<GradesTransfer>>(Result.Success,result.getData());
            }
            else{
                throw new BadRequestException(result.getErrorMessage());
            }
            return responseMessage;
        };
    }
}
